{extend name="$basepop" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>

{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>客服名称:</dt>
		<dd>
			<input type="text" id="kf_name" class="input-common">
			<p class="error">请输入客服名称</p>
			<p class="hint">设置客服名称</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>排序:</dt>
		<dd>
			<input type="number" id="kf_sort" value="0" class="input-common">
			<p class="error">请输入排序ID</p>
			<p class="hint">设置排序ID</p>
		</dd>
	</dl>
	<dl>
		<dt>客服说明:</dt>
		<dd>
			<input type="number" id="kf_desc" class="input-common">
			<p class="error">请输入说明</p>
			<p class="hint">设置说明</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>客服二维码：</dt>
		<dd>
			<div class="upload-btn-common">
				<div>
					<input class="input-file" name="file_upload" id="uploadImgweb_qrcode" type="file" onchange="imgUpload(this);" title="上传">
					<input type="hidden" id="mill_pic" value="" />
				</div>
				<input type="text" id="text_mill_pic" class="input-common" readonly="readonly" value="" />
				<em>上传</em>

				<img id="preview_web_qrcode" src="__STATIC__/blue/img/upload-common-select.png" data-html="true" data-container="body" data-placement="top" data-trigger="manual"/>

			</div>

			<p class="hint">
				<span>建议使用<i class="important-note">宽100</i>像素-<i class="important-note">高100</i>像素内的<i class="important-note">GIF</i>或<i class="important-note">PNG</i>透明图片</span>
			</p>

		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>状态:</dt>
		<dd>
			<input id="status" type="checkbox"  class="checkbox" />
			<p class="hint">设置启用状态</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="addGift();">保存</button>
		</dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>	
     var flag = false;//防止重复提交
	//保存
	function addGift(){
		var kf_name = $("#kf_name").val();
        var kf_sort = $("#kf_sort").val();
        var kf_desc = $("#kf_desc").val();
        var status = $("#status").prop('checked') ? 1 : 0 ;
        var mill_pic = $("#mill_pic").val();

		if (kf_name == '') {
			$("#kf_name").next().show().css("display","inline-block");
			$("#kf_name").focus();
			return false;
		} else {
			$(".error").hide();
		}

        if (kf_sort == '') {
            $("#kf_sort").next().show().css("display","inline-block");
            $("#kf_sort").focus();
            return false;
        } else {
            $(".error").hide();
        }
        if (mill_pic == '') {
            $("#mill_pic").next().show().css("display","inline-block");
            $("#mill_pic").focus();
            return false;
        } else {
            $(".error").hide();
        }



        if(flag){
			return false;
		}
		flag = true;
		$.ajax({
			type : "post",
			url : document.location,
			data : {
				'kf_name' : kf_name,
				'kf_sort' : kf_sort,
                'kf_desc' : kf_desc,
				'mill_pic' : mill_pic,
                'status' : status
			},
			async : true,
			success : function(data) {
				//alert(JSON.stringify(data));
				if (data["code"] > 0) {
					showMessage('success', data["message"]);
                    setTimeout('parent.close_Layer();parent.location.reload()',2000);
				}else{
					showMessage('error', data["message"]);
				}	
				flag = false;
			}
		});
	}

	 function imgUpload(event) {
		 var fileid = $(event).attr("id");
		 var id = $(event).next().attr("id");
		 var data = { 'file_path' : "config" };
		 uploadFile({
			 url: __URL(ADMINMAIN + '/kefu/uploadimage'),
			 fileId: fileid,
			 data : data,
			 callBack: function (res) {
				 if(res.code){
					 $("#"+id).val(res.data.path);
					 $("#text_" + id).val(res.data.path);
					 $("#preview_" + id).attr("data-src",__IMG(res.data.path));
					 showTip(res.message,"success");
				 }else{
					 showTip(res.message,"error");
				 }
			 }
		 });
	 }
</script>
{/block}